<%--
  Created by IntelliJ IDEA.
  User: liuxi
  Date: 2018/6/12
  Time: 17:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/statics/sweetalert.css"/>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/sweetalert.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/jquery-3.2.1.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/date/Moment.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<div class="container" style="margin-top: 50px">
    <table id="tb"></table>
</div>
<%--分配角色模态框--%>
<div id="myModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form action="${pageContext.request.contextPath}/Nurse/updateRole" method="post">
                <h3>当前角色</h3>
                <input type="hidden" name="nId" id="nId"/>
                <input type="hidden" name="dDepartmentId" id="dDepartmentId"/>
                <select id="posId" name="posId" class="form-control">
                    <%--<option value="${data.posId}" <c:if test="${data.posId==posId}">selected</c:if> >${data.posName}</option>--%>
                </select>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary add">分配</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script type="text/javascript">
    var posId;
    window.operateEvents = {
        "click .distributionRole": function (e, value, row, index) {
            posId = row.posId;
            $("#nId").val(row.nId);
            $("#dDepartmentId").val(row.dDepartmentId);
            $.ajax({
                "url": '${pageContext.request.contextPath}/Nurse/queryPosition',
                "type": "post",
                "dataType": "json",
                "success": function (data) {
                    $("#posId").empty();
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].posId == posId) {
                            $("#posId").append("<option value='" + data[i].posId + "' selected  >" + data[i].posName + "</option>");
                        } else {
                            $("#posId").append("<option value='" + data[i].posId + "'>" + data[i].posName + "</option>");
                        }

                    }
                }
            });
            $("#myModal").modal('show');
        }
    };

    $(function () {
        //bootstrapTable
        $("#tb").bootstrapTable({
            url: '${pageContext.request.contextPath}/Nurse/distributionRole',
            columns: [{
                field: 'nId',
                title: '编号'
            }, {
                field: 'nName',
                title: '职员名字'
            }, {
                title: '职位',
                formatter: function (index, row, value) {
                    if (row.posId == 1) {
                        return "护士";
                    } else if (row.posId == 2) {
                        return "医生";
                    } else if (row.posId == 3) {
                        return "主任"
                    } else if (row.posId == 4) {
                        return "药房人员";
                    } else if (row.posId == 5) {
                        return "医技医生";
                    }else if(row.posId==6){
                        return "管理员";
                    }
                }
            }, {
                title: '操作',
                events: operateEvents,
                formatter: caozuo
            }],
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            height: 500,
            pageList: [5, 10, 15],
            pageSize: 5,
            sortable: true,
            sortOrder: "asc",
            pageNumber: 1,
            pagination: true,
            queryParamsType: '',
            sidePagination: 'server'
        });

        function caozuo(value, row, index) {
            return [
                "<a class='distributionRole' href=javascript:del()>分配角色</a>"
            ].join("");
        }
    });
</script>
</html>
